package com.cpe.transfer.manager;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.cpe.data.domain.manager.Manager;
import com.cpe.data.domain.manager.ManagerForm;
import com.cpe.data.domain.manager.ManagerInfo;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;

@Component
public class ManagerTransfer {
	/**
	 * 实体-->响应
	 */
	public ManagerInfo toInfo(Manager manager) {
		Assert.notNull(manager);
		ManagerInfo info = new ManagerInfo();
		BeanUtils.copyProperties(manager, info);
		info.setCreator(manager.getCreatorRef());
		return info;
	}

	/**
	 * 实体分页-->响应分页
	 */
	public PageInfo<ManagerInfo> toPageInfo(List<Manager> managers) {
		Assert.notNull(managers);
		PageInfo<Manager> pageInfo = new PageInfo<>(managers);
		PageInfo<ManagerInfo> pageResp = new PageInfo<>();
		BeanUtils.copyProperties(pageInfo, pageResp);
		List<ManagerInfo> infoList = Lists.newArrayList();
		for (Manager manager : managers) {
			infoList.add(toInfo(manager));
		}
		pageResp.setList(infoList);
		return pageResp;
	}

	/**
	 * 表单-->实体
	 */
	public Manager toDocument(ManagerForm form) {
		Assert.notNull(form);
		Manager manager = new Manager();
		BeanUtils.copyProperties(form, manager);
		return manager;
	}
}
